<template>
	<tm-app ref='staff'>
		<tm-navbar title="猪仔详情" color='#4888ff' :hideHome="true" :fontSize="34"/>
		
		<view v-if='state==1'>
			<ezplayer
			    id="ezplayer"
			    :accessToken="cameraUrl[0]?.accessToken"
			    :url="cameraUrl[0]?.url"
			    plugins=""
			    recPlayTime=""
			    width="100%"
			    height="250"
			/>
		</view>
		
		<tm-form @submit="confirm" ref="form" v-model="staffForm" :labelWidth="200">
			<tm-form-item label="猪仔名称：" field="avatar">
				<tm-text :label="itemData.name"/>
			</tm-form-item>
			<tm-form-item label="猪仔品种：" field="breed">
				<tm-text :label="itemData.breed?.name"/>
			</tm-form-item>
			<tm-form-item label="耳标编号：" >
				<tm-text :label="itemData.rfid?.beaconMac"/>
			</tm-form-item>
			<tm-form-item label="所属猪圈：" field="circleNum">
				<tm-input v-if="state==='0'"/>
				<tm-text v-else :label="itemData.pigsty?.name"/>
			</tm-form-item>
			<tm-form-item label="入栏日龄：">
				<tm-text :label='itemData.pigLevel?.day'/>
			</tm-form-item>
			<tm-form-item label="预估体重：">
				<tm-input v-if="state==='0'"/>
				<tm-text v-else :label="itemData.pigLevel?.weight"/>
			</tm-form-item>
			<tm-form-item label="喂养人：">
				<tm-text :label="itemData.staff?.name"/>
			</tm-form-item>
			<tm-form-item>
				<tm-button v-if="state==0" form-type="submit" label="提交" block/>
			</tm-form-item>
		</tm-form> 
	</tm-app>
</template>

<script setup lang='ts' module="ezuikit">
	import { ref } from 'vue'
	import { onLoad,onShow } from "@dcloudio/uni-app";
	
	const state = ref(null)
	const itemData = ref([])
	const cameraUrl = ref([])
	
	onLoad((option)=>{
		state.value = option.state
		itemData.value = JSON.parse(decodeURIComponent(option.data))
		itemData.value.pigsty.cameraUrl.forEach(item =>{
			const val = JSON.parse(item)
			
			// split方法
			const arr = val.url.split('/')
			// console.log(arr,'拆分的url');
			const numArr = arr[4].split('.')
			arr[4] = numArr[0]
			arr[5] = numArr[2]
			const url = arr.join('/')
			// console.log(url,'组装的url');
			val.url = url
			
			cameraUrl.value.push(val)
		})
	})
	
	const staffForm = ref({
		avatar:null,
		name:null,
		phone:null,
	})
	const confirm = () => {
		
	}

	
</script>

<style>

</style>
